@extends('frontend/layouts/default')

@section('content')

<h1>All Account</h1>

<p>{{ link_to_route('nd.master.account.create', 'Add new Account', null, array('class' => 'btn btn-info')) }}</p>

@if ($accounts->count())
<table class="table table-striped table-bordered">
    <thead>
        <tr>
<th>Id</th>
<th>Domainid</th>
<th>Code</th>
<th>Class</th>
<th>Name</th>
<th>Lname</th>
<th>Uname</th>
<th>Ename</th>
<th>Nameid</th>
<th>Type</th>
<th>Balance</th>
<th>Abstract</th>
<th>Nillable</th>
<th>Node_parent</th>
<th>Node_left</th>
<th>Node_right</th>
<th>Node_depth</th>
<th> Action  </th>
        </tr>
    </thead>
    <tbody>
        @foreach ($accounts as $account)
        <tr>
<td>{{ $account->id }}</td>
<td>{{ $account->domainid }}</td>
<td>{{ $account->code }}</td>
<td>{{ $account->class }}</td>
<td>{{ $account->name }}</td>
<td>{{ $account->lname }}</td>
<td>{{ $account->uname }}</td>
<td>{{ $account->ename }}</td>
<td>{{ $account->nameid }}</td>
<td>{{ $account->type }}</td>
<td>{{ $account->balance }}</td>
<td>{{ $account->abstract }}</td>
<td>{{ $account->nillable }}</td>
<td>{{ $account->node_parent }}</td>
<td>{{ $account->node_left }}</td>
<td>{{ $account->node_right }}</td>
<td>{{ $account->node_depth }}</td>
<td>  
{{ Form::open(array('method' => 'DELETE', 'route' => array('nd.master.account.destroy', $account->id))) }} 
{{ link_to_route('nd.master.account.edit', 'Edit', $account->id, array('class' => 'btn btn-info')) }} &nbsp;&nbsp;
{{ link_to_route('nd.master.account.show', 'Show', $account->id, array('class' => 'btn btn-primary')) }} &nbsp;&nbsp;
{{ link_to_route('nd.master.account.up', 'Up', $account->id, array('class' => 'btn btn-primary')) }} &nbsp;&nbsp;
{{ link_to_route('nd.master.account.down', 'Down', $account->id, array('class' => 'btn btn-primary')) }} &nbsp;&nbsp;
{{ Form::submit('Delete', array('class' => 'btn btn-danger')) }} 
{{ Form::close() }} 
</td>
        </tr>
        @endforeach
    </tbody>
</table>
@else
    There are no accounts
@endif

<div class="container">
    <h4>accounts tree</h4>
    <div id="tree-accounts-view"></div>
</div>
<button id="refresh">Refresh accounts</button>

@stop

@section('pagestyles')
    <link rel="stylesheet" href="{{ asset('assets/tree/backbone-treeview.css') }}" />
@stop

@section('pagescripts')

<script type="text/template" id = "tree-accounts-template">
<span class="node-collapse"> 
    <span class="node-label"><%- name %></span>
    <span class="node-data">
        id:<%- id %> parent:<%- node_parent %> left:<%- node_left %> right:<%- node_right %> depth:<%- node_depth %>
    </span>
    <span class="node-action pull-right">
        <a class="btn btn-mini btn-info" href="{{URL::current()}}/<%- id %>/edit">Edit</a>
        <a class="btn btn-mini btn-primary" href="{{URL::current()}}/<%- id %>">Show</a>
        <a class="btn btn-mini btn-primary" href="{{URL::current()}}/<%- id %>/up" >Up</a>
        <a class="btn btn-mini btn-primary" href="{{URL::current()}}/<%- id %>/down" >Down</a>
        <a class="btn btn-mini btn-danger" href="{{URL::current()}}/<%- id %>" data-method="DELETE">Delete</a>
    </span>
</span>

</script>
<script src="{{ asset('assets/tree/backbone-treeview.js') }}"></script>
<script type="text/javascript">
(function(){
var treeAccountCollection = new Backbone.TreeNodeCollection( {{$jsonAccount}} );
var treeAccountCollectionView = new Backbone.TreeNodeCollectionView({
    collection: treeAccountCollection,
    nodetemplate: '#tree-accounts-template',
    nodeid : null});
$('#tree-accounts-view').html(treeAccountCollectionView.render().el);
})();
</script>

@stop

